package org.grow.yc.exception;

import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: xwg
 * @CreateDate: 2024/10/14
 */

//统一异常处理器
@RestControllerAdvice
public class ExceptionBridge {

//    捕获Controller中产生的特定类型的异常
    @ExceptionHandler
    public ResponseEntity<String> billStateHandler(BillStateException exception){
//        将捕获到的异常转换为特定的非200状态码响应给前端
//        System.out.println("BillStateException ::::: "+exception.getMessage());
        return ResponseEntity.status(666).body(exception.getMessage());
    }
    @ExceptionHandler
    public ResponseEntity<String> missTargetHandler(MissTargetException exception){
        System.out.println("--------------");
//        System.out.println("MissTargetException ::::"+exception.getMessage());
        ResponseEntity<String> a = ResponseEntity.status(888).body(exception.getMessage());
        System.out.println(a+ a.getClass().getName());
        return  a;
    }
}
